<?php
namespace app\hongguan\controller;

use think\Controller;
use think\Db;

class Index extends Controller
{
    // 网站首页
    public function index()
    {
        //return view();
        // 查询导航菜单
        $caidan = Db::name('caidan')->select();
        // 查询banner图
        $bunner = Db::name('bunner')->select();
        // 查询通知公告
        // 查询最新一个视频
        $gonggaoVideo = Db::name('gonggao')
            ->field('id,title,cover,createtime')
            ->where('type', '=', 2)
            ->order('createtime', 'desc')
            ->limit(0,1)
            ->find();
        // 处理日期
        $gonggaoVideo['date'] = date('Y-m', strtotime($gonggaoVideo['createtime']));
        $gonggaoVideo['day'] = date('d', strtotime($gonggaoVideo['createtime']));;
       // 查询5条最新的公告
        $gonggaoList = Db::name('gonggao')
            ->field('id,title,createtime')
            ->where('type', '=', 1)
            ->order('createtime', 'desc')
            ->limit(0,5)
            ->select();
        //查询主题教育
        $zhuti = DB::name('zhuti')
            ->field('id,title,image,createtime')
            ->order('createtime','desc')
            ->limit(0,3)
            ->select();
        //处理时间
        foreach ($zhuti as $k => $v) {
            $zhuti[$k]['date'] = date('Y-m-d', strtotime($zhuti[$k]['createtime']));
        }

        //查询工作动态
        $gongzuodongtai = DB::name('gongzuodongtai')
            ->field('id,title,zhaiyao,createtime')
            ->order('createtime','desc')
            ->limit(0,4)
            ->select();
        //处理时间
        foreach ($gongzuodongtai as $k=>$v){
            $gongzuodongtai[$k]['date']=date('Y-m', strtotime($gongzuodongtai[$k]['createtime']));
            $gongzuodongtai[$k]['day']=date('d', strtotime($gongzuodongtai[$k]['createtime']));;
        }
        //查询一条带图工作动态
        $gongzuodongtai2 = DB::name('gongzuodongtai')
            ->field('id,title,image')
            ->limit(0,1)
            ->find();
        //查询社会服务
        $shehuifuwu=DB::name('shehuifuwu')
            ->field('id,title,zhaiyao,createtime')
            ->order('createtime','desc')
            ->limit(0,4)
            ->select();
        //处理时间
        foreach ($shehuifuwu as $k => $v) {
            $shehuifuwu[$k]['date'] = date('Y-m-d', strtotime($shehuifuwu[$k]['createtime']));
        }
        //链接
        $youqinglianjie=DB::name('youqinglianjie')
            ->select();
        //展厅
        //大图
        $zhanting1=DB::name('zhanting')
             ->field('id,image')
            ->where('type','=',1)
             ->limit(0,2)
             ->select();
        //小图
        $zhanting2=DB::name('zhanting')
            ->field('id,image')
            ->where('type','=',2)
            ->limit(0,4)
            ->select();
       // halt($zhanting2);
        //查询页脚
       $dibu= DB::name('dibu')
            ->field('id,title,content')
            ->limit(0,5)
            ->select();

        return view('index2', [
            'caidan' => $caidan,
            'banner' => $bunner,
            'gonggaoVideo' => $gonggaoVideo,
            'gonggaoList' => $gonggaoList,
            'zhuti'=>$zhuti,
            'gongzuodongtai'=>$gongzuodongtai,
            'gongzuodongtai2'=>$gongzuodongtai2,
            'shehuifuwu'=>$shehuifuwu,
            'youqinglianjie'=>$youqinglianjie,
            'zhanting1'=>$zhanting1,
            'zhanting2'=>$zhanting2,
            'dibu'=>$dibu,
        ]);
    }
    //红馆简介
    public function cardList()
    {
        // 接收搜索的关键字
        $sousuozhi = input('sousuozhi');
        $where = [];
        if (!empty($sousuozhi)) {
            $where['title'] = ['like', '%'.$sousuozhi.'%'];
        }
        // 查询导航菜单
        $caidan = Db::name('caidan')->select();
        // 查询banner图
        $bunner = Db::name('bunner')->select();
        //查询主题教育
        $jianjie = DB::name('jianjie')
            ->field('id,title,image,content,createtime')
            ->where($where)
            ->order('createtime','desc')
            ->limit(0,4)
            ->select();
        //处理时间
        foreach ($jianjie as $k => $v) {
            $jianjie[$k]['date'] = date('Y-m-d', strtotime($jianjie[$k]['createtime']));
        }

        return view('cardList', [
            'caidan' => $caidan,
            'banner' => $bunner,
            'jianjie'=>$jianjie,
        ]);
    }
}